security(wallet): encrypt MMKV wallet vault with device-bound keychai… - #134
Merged
cybermax4200 merged 1 commit intoAug 26, 2026
Merged
Conversation
…n key Closes ecotask-network#122 - Derive a 32-byte AES key via crypto.getRandomValues and store it in the OS secure enclave (react-native-keychain, WHEN_UNLOCKED_THIS_DEVICE_ONLY). - Open the wallet vault MMKV instance with that encryptionKey instead of plaintext. - Add a one-time migration that moves existing plaintext secrets from the legacy 'wallet-vault' instance into the encrypted 'wallet-vault-secure' instance, then deletes the plaintext MMKV file. - Add react-native-keychain as a pinned dependency. - Wire initWalletVault() into App startup; public API stays synchronous. - Extend walletVault tests with keychain + MMKV mocks covering migration.
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #122
—
walletVaultwas opening a plaintext MMKV instance (new MMKV({ id: 'wallet-vault' })), so every Stellar secret seed was written as cleartext to the device's MMKV flat-file, exposed to rooted devices / ADB pull / backup extraction.This encrypts the wallet vault with an AES key that is generated per-device and bound to the OS secure enclave (iOS Keychain / Android Keystore via
react-native-keychain), and transparently migrates any existing plaintext secrets.Changes
src/services/walletVault.ts:crypto.getRandomValuesand store it in the secure enclave (WHEN_UNLOCKED_THIS_DEVICE_ONLY,SECURE_HARDWARE), with an ANY/software fallback for Android < API 23.new MMKV({ id: 'wallet-vault-secure', encryptionKey: key }).initWalletVault()(async, idempotent) loads/creates the key, builds the encrypted store, and runs a one-time migration: copy everysecret:*key from the legacy plaintextwallet-vaultinstance into the encrypted instance → delete from legacy →MMKV.removeMMKV('wallet-vault')removes the plaintext file (guarded by a migration flag).saveSecret/getInAppSecret/hasInAppSecret/clearInAppSecretremain synchronous; the secret value is never logged or written to JS state / Zustand.App.tsx— callsinitWalletVault()at startup.package.json—react-native-keychainadded as a pinned dependency.Tests/mocks— root__mocks__/react-native-keychain.js(auto-applied so all suites importingwalletVaultresolve it); extendedsrc/__tests__/__mocks__/setup.tsMMKV mock (per-instancegetAllKeys/clear/removeMMKVidentitycreateJSONStorage);walletVault.test.tsextended with keychain + mock-MMKV migration coverage;useStellarWallet.test.tsxinitializes the vault.Acceptance criteria
encryptionKeyfrom the OS secure enclave.react-native-keychainadded as a pinned dependency (iOS/Android).walletVault.test.tstests still pass with keychain mocked.Verification
tsc --noEmit: cleaneslint(changed files): 0 errorsjest: 387/387 passingNotes / out of scope
pod install/ Gradle) is the platform build step; the dependency is added and consumed here.signChallengeXDR/buildPaymentXDRare intentionally out of scope.